package edu.guet.server.mapper;

import edu.guet.server.model.dto.NoticeDTO;
import edu.guet.server.model.vo.NoticeVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NoticeMapper {
    @Insert("INSERT INTO notice (semester_id, notice_title, notice_content) " +
            "VALUES (#{semesterId}, #{noticeTitle}, #{noticeContent})")
    public void addNotice(Integer semesterId, String noticeTitle, String noticeContent);

    /**
     * 根据学期课程id搜索最新一条公告
     * @param semesterId
     * 如果不加时间了的话，暂时只能以主键倒序排出最新一条notice了
     */
    @Select("select * from notice where semester_id=#{semesterId} " +
            "ORDER BY notice_id DESC limit 1;")
    NoticeVO findlastNoticeBysemesterId(Integer semesterId);

    @Select("select * from  notice where semester_id=#{semesterId}")
    List<NoticeVO> selectNotice(Integer semesterId);


    @Delete("DELETE FROM notice where notice_id=#{noticeId}")
    void deleteNotice(Integer noticeId);

    @Update("UPDATE notice set notice_title=#{notice_title},notice_content=#{notice_content} , update_time=current_timestamp where notice_id=#{notice_id}")
    Integer updateNotice(NoticeDTO noticeDTO);
}
